package com.twentytwok.hospitalsystem22K;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.write.builder.ExcelWriterBuilder;
import com.alibaba.excel.write.builder.ExcelWriterSheetBuilder;
import com.twentytwok.hospitalsystem22K.pojo.Department;
import com.twentytwok.hospitalsystem22K.service.DepartmentService;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;

import java.util.List;


/**
 * 测试类
 */
@SpringJUnitConfig(locations = {"classpath:applicationContext.xml", "classpath:springmvc.xml"})
public class Demo {
    @Autowired
    private DepartmentService departmentService;


    @Test
    public void test2() {
        //写数据到 excel 中
        //工作簿对象
        ExcelWriterBuilder writerBuilder = EasyExcel.write("test.xlsx", Department.class);

        ExcelWriterSheetBuilder sheet = writerBuilder.sheet();

        // List<Department> departments = Arrays.asList(new Department(1, "zs", 10, "pic", true), new Department(2, "ls", 1, "pic", false));

        // sheet.doWrite(departments);
    }

    @Test
    public void exportExcel() {
        List<Department> departments = departmentService.selectAllDepartment();

        ExcelWriterBuilder writerBuilder = EasyExcel.write("test.xlsx", Department.class);

        ExcelWriterSheetBuilder sheet = writerBuilder.sheet();

        sheet.doWrite(departments);
    }
}
